package com.zyfdroid.backupftpserver.ftplets;

import android.content.Context;
import android.content.pm.PackageManager;

import com.zyfdroid.backupftpserver.LastModifiedStorageHelper;
import com.zyfdroid.backupftpserver.SAFHelper;
import org.apache.ftpserver.ftplet.FtpFile;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

public class RootFtpFile implements FtpFile {
    @Override
    public String getAbsolutePath() {
        return "/";
    }

    @Override
    public String getName() {
        return "/";
    }

    @Override
    public boolean isHidden() {
        return false;
    }

    @Override
    public boolean isDirectory() {
        return true;
    }

    @Override
    public boolean isFile() {
        return false;
    }

    @Override
    public boolean doesExist() {
        return true;
    }

    @Override
    public boolean isReadable() {
        return true;
    }

    @Override
    public boolean isWritable() {
        return false;
    }

    @Override
    public boolean isRemovable() {
        return false;
    }

    @Override
    public String getOwnerName() {
        return "rootfs";
    }

    @Override
    public String getGroupName() {
        return "root";
    }

    @Override
    public int getLinkCount() {
        return 1;
    }

    @Override
    public long getLastModified() {
        return 0;
    }

    @Override
    public boolean setLastModified(long l) {
        return false;
    }

    @Override
    public long getSize() {
        return 0;
    }

    @Override
    public Object getPhysicalFile() {
        return null;
    }

    @Override
    public boolean mkdir() {
        return false;
    }

    @Override
    public boolean delete() {
        return false;
    }

    @Override
    public boolean move(FtpFile ftpFile) {
        return false;
    }

    @Override
    public List<? extends FtpFile> listFiles() {
        List<FtpFile> ff = new ArrayList<>();
        ff.add(new AppContainerFtpFile(pm));
        ff.add(new SdcardRootFtpFile());
        ff.add(safFileSystemManager);
        return ff;
    }

    PackageManager pm;
    Context ctx;
    SAFFileSystemManager safFileSystemManager;

    public RootFtpFile(PackageManager pm,Context ctx, SAFFileSystemManager safFileSystemManager) {
        this.pm = pm;
        this.safFileSystemManager = safFileSystemManager;
        this.ctx = ctx;
    }

    @Override
    public OutputStream createOutputStream(long l) throws IOException {
        throw new IOException("👴是目录");
    }

    @Override
    public InputStream createInputStream(long l) throws IOException {
        throw new IOException("👴是目录");
    }
}
